package com.wu.store.service.impl;

import com.wu.store.dao.ParamsDao;
import com.wu.store.entity.Brand;
import com.wu.store.entity.Params;
import com.wu.store.service.ParamsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParamsServiceImpl implements ParamsService {

	@Autowired
	private ParamsDao paramsDao;

	@Override
	public List<Params> list(String keyword) {
		return paramsDao.list(keyword);
	}

	@Override
	public boolean save(Params params) throws Exception {
		int affectedRow;
		if (StringUtils.isEmpty(params.getName())) {
			throw new Exception("参数名称不能为空");
		}
		if (params.getId() == null) {
			affectedRow = paramsDao.add(params);
		} else {
			affectedRow = paramsDao.update(params);
		}
		if (affectedRow == 0) {
			throw new Exception("操作失败");
		}
		return true;
	}
}
